]> dgit.raspbian.org Git - gnome-shell.git/commitdiff
modalDialog: Don't use a for...in loop for iterating over arrays.
authorJasper St. Pierre <jstpierre@mecheye.net>
Mon, 19 Sep 2011 00:40:21 +0000 (20:40 -0400)
committerJasper St. Pierre <jstpierre@mecheye.net>
Mon, 19 Sep 2011 17:42:47 +0000 (13:42 -0400)
for...in loops do not guarantee that the indexes iterate in order. As a
consequence, buttons may appear in an undesired order.

js/ui/modalDialog.js

index 49f086b2c30039a8864ca0371ce6bbdf1d1fc04b..80615870c423c768ffd940bc7e646b8f1714db56 100644 (file)
@@ -110,9 +110,8 @@ ModalDialog.prototype = {
         this._buttonLayout.destroy_children();
         this._actionKeys = {};
 
-        let i = 0;
-        for (let index in buttons) {
-            let buttonInfo = buttons[index];
+        for (let i = 0; i < buttons.length; i ++) {
+            let buttonInfo = buttons[i];
             let label = buttonInfo['label'];
             let action = buttonInfo['action'];
             let key = buttonInfo['key'];
@@ -144,11 +143,10 @@ ModalDialog.prototype = {
 
             if (key)
                 this._actionKeys[key] = action;
-            i++;
         }
 
         // Fade in buttons if there weren't any before
-        if (!hadChildren && i > 0) {
+        if (!hadChildren && buttons.length > 0) {
             this._buttonLayout.opacity = 0;
             Tweener.addTween(this._buttonLayout,
                              { opacity: 255,